import requests


def get_resp(time, sing):
    cookies = {
        'HWWAFSESID': '27f4f82353b3814132',
        'HWWAFSESTIME': '1733383547067',
        'hasTelegraphNotification': 'on',
        'hasTelegraphRemind': 'on',
        'hasTelegraphSound': 'on',
        'vipNotificationState': 'on',
        'tfstk': 'fMJjGADTXr4XhvhqOlnPPggpCaBsL0JsLor6xHQa35BvPPKpx1p27ZR55U_kQIWN7lZDFewa3qcDXR6NB2uELv-D0OXt8IMM5JEcbisADP5te7UaUTriLv-DDKZXh3ke3TJrnwbOBsCY2YQlDNUvW1eJ2ajGXrITH0i5jaITHiQTwaI1joBOBFK-ViDTakssGZxj4BaPW6ogD_b7BJthcsUkj5yULyScMwH3bRws9i1fJnQS-k5xD_KG1dqgC1-vtFjpkr31SLtJHBLKzS7vOGte1enaig56nT_9HvqCyKt6FsAzkSIChZ1pHsZExnf9NL62HVVH43_AOTRrZq5NhEOh-shorFt5uFpfwrgP7B-yH_TKz8TG1CpVeK3-dgobLwGYM5Z5tRs580i7s5XH7-xplV9MfsIlc_oSVrdGMgj580i7s5fAqi_rV0avs',
    }

    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
        'Connection': 'keep-alive',
        'Content-Type': 'application/json;charset=utf-8',
        # 'Cookie': 'HWWAFSESID=27f4f82353b3814132; HWWAFSESTIME=1733383547067; hasTelegraphNotification=on; hasTelegraphRemind=on; hasTelegraphSound=on; vipNotificationState=on; tfstk=fMJjGADTXr4XhvhqOlnPPggpCaBsL0JsLor6xHQa35BvPPKpx1p27ZR55U_kQIWN7lZDFewa3qcDXR6NB2uELv-D0OXt8IMM5JEcbisADP5te7UaUTriLv-DDKZXh3ke3TJrnwbOBsCY2YQlDNUvW1eJ2ajGXrITH0i5jaITHiQTwaI1joBOBFK-ViDTakssGZxj4BaPW6ogD_b7BJthcsUkj5yULyScMwH3bRws9i1fJnQS-k5xD_KG1dqgC1-vtFjpkr31SLtJHBLKzS7vOGte1enaig56nT_9HvqCyKt6FsAzkSIChZ1pHsZExnf9NL62HVVH43_AOTRrZq5NhEOh-shorFt5uFpfwrgP7B-yH_TKz8TG1CpVeK3-dgobLwGYM5Z5tRs580i7s5XH7-xplV9MfsIlc_oSVrdGMgj580i7s5fAqi_rV0avs',
        'Referer': 'https://www.cls.cn/depth?id=1003',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0',
        'sec-ch-ua': '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
    }

    # 根据时间戳进行分页
    params = {
        'app': 'CailianpressWeb',
        'category': '',
        'lastTime': time,
        'last_time': time,
        'os': 'web',
        'refresh_type': '1',
        'rn': '20',
        'sv': '8.4.6',
        'sign': sing
    }

    response = requests.get('https://www.cls.cn/nodeapi/telegraphList', params=params, cookies=cookies, headers=headers)
    return response.json()


def sing_t(my_time):
    import execjs
    with open("t.js", 'r', encoding='utf-8') as f:
        js_code = f.read()

    result = execjs.compile(js_code).call('main', my_time)
    # print(response)
    return result


def echo():
    import time
    time2 = round(time.time())
    for i in range(1, 11):
        time2 = time2 - 3000
        sing = sing_t(time2)
        print(sing)
        data = get_resp(time2, sing)
        print(data)
        time.sleep(3)


echo()
